package com.thread.demo.thread;

public class RunnableTest {

    public static void main(String[] args) {
        class MyRunnable implements Runnable {
            private int ticket = 10;

            @Override
            public void run() {
                for(int i=0; i<20; i++) {
                    if(this.ticket >0) {
                        System.out.println(Thread.currentThread().getName() + "买票：ticket" + this.ticket--);
                    }
                }
            }
        }
        MyRunnable runnable = new MyRunnable();
        Thread thread1 = new Thread(runnable);
        Thread thread2 = new Thread(runnable);
        Thread thread3 = new Thread(runnable);
        thread1.start();
        thread2.start();
        thread3.start();
    }


}
